<template>
  <div class="container">
    <div class="bg"></div>
    <div class="right">
      <div class="login-panel">
        <div class="handoff">
          切换登录方式
        </div>
        <h3>医疗机构版扫码登录</h3>
        <div class="login-block">
          <div class="user">
            <el-input v-model="formData.user"/>
          </div>
          <div class="user user1">
            <el-input type="password" v-model="formData.pwd"/>
          </div>
        </div>
        <div class="record-pwd">
          <div class="record-p" @click="changeEvent">
            <el-checkbox style="margin-right: 5px;" @change="changeEvent" v-model="checked1" size="large"/>
            记住用户名
          </div>
          <div class="find-pwd">找回密码</div>
        </div>
        <div style="margin-left: 28px;color: red;" v-if="ispwd">账户或者密码不对</div>
        <div class="login-btn-block">
          <div class="logn-btn" style="margin-bottom: 15px;" @click="login">登 录</div>
          <div class="logn-btn">人脸识别登录</div>
          <div class="face-p" @click="changeEvent1">
            <el-checkbox style="margin-right: 5px;" @change="changeEvent1" v-model="checked2" size="large"/>
            自动使用人脸识别登录
          </div>
        </div>
      </div>
      <div class="version">
        <div style="font-size: 16px; color: #516588">版本号：8.9.2.4</div>
        <div class="btn" @click="closeWindow">退出</div>
      </div>
    </div>
  </div>

</template>

<script lang="ts" setup>
import {ref, watch} from 'vue'
import {ElMessage, ElInput} from 'element-plus'
import dayjs from 'dayjs'
import {useRouter} from 'vue-router'
import {fa} from 'element-plus/es/locales.mjs'

let loginForm = {
  user: '262173607',
  pwd: "11162064"
}
const router = useRouter()
let formData = ref({user: '262173607', pwd: '11162064'})
let checked1 = ref(false)
let checked2 = ref(false)
let ispwd = ref(false)

const changeEvent = () => {
  checked1.value = !checked1.value
}

const changeEvent1 = () => {
  checked2.value = !checked2.value
}

const closeWindow = () => {
  // 关闭当前窗口
  window.electronAPI.closeWindow();
  //window.close()
}

const login = () => {

  //router.push('/home')

  if (!formData.value.user) {
    ElMessage.error('请输入用户名')
    return
  }
  if (!formData.value.pwd) {
    ElMessage.error('请输入密码')
    return
  }
  if ((formData.value.user === '262173607' && formData.value.pwd === '11162064')
      || (formData.value.user === 'admin' && formData.value.pwd === 'admin')) {
    // ElMessage.success('登录成功')
    router.push('/home?day=' + dayjs().format('YYYY-MM-DD HH:mm:ss') + '&user=' + formData.value.user)
  } else {
    ElMessage.error('用户名或密码错误')
  }
}

watch(formData.value, () => {
  ispwd.value = false
})

</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.container {
  display: flex;
  height: calc(100vh);

  .bg {
    flex: 1;
    background: url('../../assets/bg.png') no-repeat left center;
    background-size: cover;
    height: 100%;
  }

  .right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .login-panel {
    width: 400px;
    padding: 10px;

    .handoff {
      font-size: 16px;
      padding-top: 10px;
      font-weight: bold;
      color: #1b0ec5;
      text-align: right;
      font-family: emoji;
      height: 28px;
      background: url('../../assets/handoff.png') no-repeat 260px center;
      background-size: 9%;
      text-decoration-line: underline;
    }

    h3 {
      font-size: 20px;
      color: #516588;
      text-align: center;
      margin-top: 150px;
      font-weight: bold;
      font-family: emoji;
    }
  }

  .login-block {
    margin-top: 40px;
    padding-right: 10px;

    .user {
      padding-left: 30px;
      background: url('../../assets/login.png') no-repeat left center;
      background-size: 5%;
      margin-bottom: 20px;
    }

    .user1 {
      background: url('../../assets/pwd.png') no-repeat left center;
      background-size: 5%;
      margin-bottom: 0;
    }
  }
}

.record-pwd {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  padding-right: 10px;

  .record-p {
    padding-left: 30px;
    display: flex;
    align-items: center;
    cursor: pointer;
    color: #333;
  }

  .find-pwd {
    text-decoration-line: underline;
    color: #5c86b9;
    cursor: pointer;
  }
}

.login-btn-block {
  padding-left: 27px;
  padding-right: 10px;
  margin-top: 30px;

  .logn-btn {
    font-size: 20px;
    line-height: 40px;
    color: #fff;
    background: #516588;
    text-align: center;
    font-family: emoji;
    font-weight: bold;
  }

  .face-p {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
  }
}

.version {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px 20px 10px;

  .btn {
    border: solid 1px #d2cac7;
    line-height: 26px;
    width: 66px;
    text-align: center;
    cursor: pointer;
    font-size: 16px;
  }
}

:deep(.el-input__wrapper) {
  //background: #e0e0d6;
  border: solid 1px #969191;
  font-size: 20px;
}

:deep(.el-checkbox__inner) {
  //background: #e0e0d6;
  border: solid 1px #969191;
}

:deep(.el-checkbox__inner) {
  //background: #e0e0d6 !important;
  border: solid 1px #969191 !important;
  border-color: #333 !important;

  &::after {
    border-color: #333 !important;
  }
}
</style>
